package hu04.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ParticiparVotar
 */
@WebServlet("/ParticiparVotar")
public class ParticiparVotar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ParticiparVotar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		// Recuperar los datos del <form> -- Los datos recopilaods siempre se presentan en tipo string
        String codigoidea = request.getParameter("codigoidea");
        String calificacion = request.getParameter("calificacion");
        String comentarios = request.getParameter("comentarios");
        
        // Convertir String a int
        int puntuacion = Integer.parseInt(calificacion);
        
        // Guardar en memoria
        request.setAttribute("ResultadoCodIdea", codigoidea);
        request.setAttribute("ResultadoCalificacion", puntuacion);
        request.setAttribute("ResultadoComentarios", comentarios);
                        
        // Volver a mostrar el JSP
        RequestDispatcher rd = 
                                request.getRequestDispatcher("hu04.jsp");
        rd.forward(request, response);
	
	}

}
